﻿
$(function () {
    var catalogs = $(".Catalogs");
    $(".CategoryItem").click(function () {
        if ($(this).next(".Catalogs").css("display") != "none") return;
        catalogs.slideUp("medium");
        $(this).next(".Catalogs").slideDown("medium");
    });
    groupCaroufredselItems(".Products", 6);
    $(".Products").carouFredSel({
        direction: "left",
        pagination: "#BestSellPages",
        auto: false,
        'scroll': { 'item': 1, 'duration': 1500, 'fx': 'scroll' }
    });

    $(".marqueSlide").carouFredSel({
        direction: "up",
        auto: true,
        item: 1,
        duration: 5000
    });

    $("#ProductsRecommendItems").carouFredSel({
        direction: "left",
        pagination: "#ProductsRecommendPages",
        auto: false,
        'scroll': { 'item': 2, 'duration': 1500, 'fx': 'scroll' }
    });
    $("#ProductsNewItems").carouFredSel({
        direction: "left",
        pagination: "#ProductsNewPages",
        auto: false,
        'scroll': { 'item': 4, 'duration': 1500, 'fx': 'scroll' }
    });
});

function groupCaroufredselItems(element, itemcount) {
    var container = $(element);
    var arr = container.children();
    var i = 0;
    var html = "";
    var temphtml = "";
    var total = container.children().size();
    for (var j = 0; j < total; j++) {
        if (i++ == itemcount - 1) {
            i = 0;
            html += '<div>' + temphtml + '<div class="clear"/></div>';
            temphtml = "";
        }
        temphtml += arr[j].outerHTML;
    }
    container.html(html);
}